import {Protocol}from "./MessagePack.js"
import usart from '@ohos.multimedia.usart';
export class UsartSenderReceiver{
    constructor(int_port_num){
        this.port =int_port_num;
    }
    expectInt16(){
        const read_buffer = usart.read(this.port,2);
        const v=new DataView(read_buffer.buffer,0,2);
        const int_data=v.getInt16(0,true);
        return int_data
    }
    WifiConnect(str_name,str_password){
        usart.write(this.port,Protocol.WifiConnect(str_name,str_password));
        return this.expectInt16();
    }
    IOout(int_portname,int_IO_name){return this.b("IOout",int_portname,int_IO_name);}
    SensorInput(int_portname){return this.b("SensorInput",int_portname);}
    CameraSwitch(int_option){return this.b("CameraSwitch",int_option);}
    openCamera(){return this.b("CameraSwitch",1);}
    closeCamera(){return this.b("CameraSwitch",0);}
    ImageIdent(Int16Array_RGBs){return this.b("ImageIdent",Int16Array_RGBs)}
    FaceReg(int_timeout){return this.b("FaceReg",int_timeout);}
    ColorRange(Int16Array_RGBs,int_HSV_range){
        if(!(Int16Array_RGBs instanceof Int16Array)){throw Error("Invalid type,input is not an Int16Array!");}
        return this.b("ColorRange",Int16Array_RGBs,int_HSV_range);
    }
    CustomColor(int_h_min, int_h_max, int_s_min, int_s_max, int_v_min, int_v_max){
        return this.b("CustomColor",new Int16Array(int_h_min, int_h_max, int_s_min, int_s_max, int_v_min, int_v_max));
    }
}